package org.iks.user.enums.handlers;

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;
import org.iks.user.enums.ApplyFriendStatus;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Author kzou
 * Date 2024/5/23
 * Description: Mybatis 自定义{@link ApplyFriendStatus} handler
 */
@MappedTypes({ApplyFriendStatus.class})
@MappedJdbcTypes(JdbcType.INTEGER)
public class ApplyFriendStatusTypeHandler extends BaseTypeHandler<ApplyFriendStatus> {

    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, ApplyFriendStatus parameter, JdbcType jdbcType) throws SQLException {
        ps.setInt(i, parameter.getCode());
    }

    @Override
    public ApplyFriendStatus getNullableResult(ResultSet rs, String columnName) throws SQLException {
        int code = rs.getInt(columnName);
        return ApplyFriendStatus.of(code);
    }

    @Override
    public ApplyFriendStatus getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        int code = rs.getInt(columnIndex);
        return ApplyFriendStatus.of(code);
    }

    @Override
    public ApplyFriendStatus getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        int code = cs.getInt(columnIndex);
        return ApplyFriendStatus.of(code);
    }

}
